package com.aube.control.player;

import android.content.Context;
import android.media.AudioManager;
import android.view.Surface;

import com.huyn.baseframework.model.VideoPlayModel;
import com.huyn.baseframework.utils.Utils;

/**
 * Created by huyaonan on 16/6/27.
 * 普通vr镜头的视频处理逻辑
 */
public class VRTextureVideoHelper extends TextureVideoHelper {

    public VRTextureVideoHelper(Context context, VideoPlayModel video, ISurfaceTextureProvider provider) {
        this(context, video, false, provider);
    }

    public VRTextureVideoHelper(Context context, VideoPlayModel video, boolean enableVolume, ISurfaceTextureProvider provider) {
        this.enableVolume = enableVolume;
        this.mContext = context;
        this.iProvider = provider;
        initPlayInfo(context, video);
    }

    protected void initPlayInfo(Context context, VideoPlayModel video) {
        super.initPlayInfo(context, video);

        if(!DO_NOT_USE_CC)
            texturePrepared(getSurface());
    }

    @Override
    protected void texturePrepared(Surface surface) {
        if(surface == null)
            return;
        try {
            Utils.Log(getVideoId(), "prepare surface");
            if (mRunningOnBackground.get()) {
                mRunningOnBackground.set(false);
                //按home键暂停,会黑屏
                //player.prepareAsync();
                //player.start();
            }

            isDestroyed.set(false);

//            manageSound(enableVolume);

            if(player != null) {
                player.setSurface(surface);

                myListener = createMyListener();

                player.setAudioStreamType(AudioManager.STREAM_MUSIC);
                player.setOnBufferingUpdateListener(myListener);
                player.setOnPreparedListener(myListener);
                player.setOnCompletionListener(myListener);
                player.setOnSeekCompleteListener(myListener);
                player.setOnErrorListener(myListener);
            } else {
                textureForExoPrepared(surface);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
